package com.starwish.starwishblog.mapper;

import com.starwish.starwishblog.entity.Article;
import com.starwish.starwishblog.vo.ArticleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ArticleMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Article record);

    Article selectByPrimaryKey(Integer id);

    List<Article> selectAll();

    int updateByPrimaryKey(Article record);

    List<ArticleVo> selectArticleByCons(@Param("aname") String aname,@Param("uname")String uname);

    int updateContent(@Param("bid") Integer bid,@Param("html")String html);

    @Update("update sw_article set weight = #{weight} where id = #{id}")
    int updateWeight(@Param("id") Integer id, @Param("weight") Integer weight);

    List<ArticleVo> selectRecommendArticles();

    List<ArticleVo> selectHotArticles();

    List<ArticleVo> selectNewArticles();

    ArticleVo selectArticleById(@Param("id") Integer id);

    int insertArticle(ArticleVo articleVo);

    int update(ArticleVo article);

    List<ArticleVo> selectArticlesByCateId(@Param("cateId") Integer cateId);

    List<ArticleVo> selectArticlesByAuthorId(@Param("authorId") Integer authorId);

    List<ArticleVo> selectHotArticlesByAuthorId(@Param("authorId") Integer authorId);

    List<ArticleVo> selectNewArticlesByAuthorId(@Param("authorId") Integer authorId);

    List<ArticleVo> selectCollectionArticlesByCons(@Param("authorId") Integer authorId, @Param("type") Integer type);

    int deleteCollectionByUserIdAndArticleId(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer checkIfLike(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer checkIfCollect(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer updateArticleCollectionCount(@Param("id") Integer articleId, @Param("num") int num);

    Integer updateArticleLikeCount(@Param("id") Integer articleId, @Param("num") int num);

    Integer deleteLikeByUserIdAndArticleId(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer insertArticleLike(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer insertArticleCollection(@Param("userId") Integer userId, @Param("articleId") Integer articleId);

    Integer selectArticleCountByAuthorId(@Param("authorId") Integer authorId);

    @Update("update sw_article set view_count = view_count + 1 where id = #{articleId}")
    Integer updateArticleViewCount(@Param("articleId") Integer articleId);

    @Update("update sw_collection set type = #{type} where article_id = #{articleId} and user_id = #{userId}")
    Integer updateCollectionType(@Param("userId") Integer userId, @Param("articleId") Integer articleId,@Param("type") Integer type);

    List<ArticleVo> selectArticleByConsAndStatus(@Param("aname") String aname, @Param("uname") String uname, @Param("status") Integer status);
    //审核文章修改文章状态
    Integer updateArticleStatus(@Param("articleId") Integer articleId, @Param("status") Integer status, @Param("result") String result);

    List<ArticleVo> selectArticlesByAuthorIdAndStatus(@Param("authorId") Integer authorId, @Param("status") Integer status);

    List<ArticleVo> selectNewArticlesByAuthorIdAndStatus(@Param("authorId") Integer authorId, @Param("status") Integer status);
    List<ArticleVo> selectHotArticlesByAuthorIdAndStatus(@Param("authorId") Integer authorId, @Param("status") Integer status);

}